package com.reptile.science.service.impl;

import com.reptile.science.dao.TextMapper;
import com.reptile.science.model.TextInfo;
import com.reptile.science.service.TextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class TextServiceImpl implements TextService {

    @Autowired
    private TextMapper textMapper;

    @Override
    @Transactional
    public int save(TextInfo textInfo) {
        TextInfo param = new TextInfo();
        param.setTitle(textInfo.getTitle());
        param.setContent(textInfo.getContent());
        List<TextInfo> list = this.getList(param);
        if(list.size() == 0){
            return this.textMapper.save(textInfo);
        }
        return 0;
    }

    @Override
    public List<TextInfo> getList(TextInfo textInfo) {
        if(textInfo.getTitle() != null){
            List<TextInfo> list = this.textMapper.getList(textInfo);
            return list;
        }
        return null;
    }
}
